//
//  LoginViewController.m
//  QT
//
//  Created by 甘世清 on 2024/10/15.
//

#import "LoginViewController.h"
#import "NumberViewController.h"
@interface LoginViewController ()
@property (nonatomic , strong) SQCustomButton * yesBtn;
@property (nonatomic , strong) FSTextView * emailtextField;
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)SQ_UIViewForSelfView{
    self.view.backgroundColor = SQColor(@"#F7F7F7");
    UILabel * label = [[UILabel alloc]init];
    label.text = SQNSLocalString(@"手机号码");
    label.font = FONT_REGULAR(22);
    label.textColor = SQColor333333;
    [self.view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(30);
        make.top.equalTo(self.view).offset(100+TopHeight);
    }];
    
    UILabel * label1 = [[UILabel alloc]init];
    label1.text = SQNSLocalString(@"未注册用户填写手机号进行注册");
    label1.font = FONT_REGULAR(10);
    label1.textColor = SQColor999999;
    [self.view addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(30);
        make.top.equalTo(label.mas_bottom).offset(10);
    }];
    
    UIView * bgView = [[UIView alloc]init];
    bgView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.top.equalTo(label1.mas_bottom).offset(20);
    }];
    UILabel * label86 = [[UILabel alloc]init];
    label86.text = @"+86";
    label86.font = FONT_MEDIUM(14);
    label86.textColor = SQColor333333;
    [bgView addSubview:label86];
    [label86 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(bgView).offset(16);
            make.centerY.equalTo(bgView);
    }];
    UIView * lineView = [[UIView alloc]init];
    lineView .backgroundColor = SQColor(@"#E0E0E0");
    [bgView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(1);
            make.centerY.equalTo(bgView);
            make.height.mas_equalTo(26);
            make.left.equalTo(bgView).offset(64);
    }];
    
    [bgView addSubview:self.emailtextField];
    [self.emailtextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bgView).offset(7);
        make.left.equalTo(bgView).offset(100);
        make.height.mas_equalTo(50);
        make.right.equalTo(bgView.mas_right);
    }];
    [self.emailtextField becomeFirstResponder];
    
    [self.view addSubview:self.yesBtn];
    [self.yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(70);
            make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view).offset(-20);
    }];
    
    self.emailtextField.text = @"13183366155";
    
    WS(weakSelf);
    [self.emailtextField addTextDidChangeHandler:^(FSTextView *textView) {
        if ([textView.formatText isNotEmpty]) {
            weakSelf.yesBtn.image = SQGetImage(@"pic_denglu_anniu_jianbian");
        } else {
            weakSelf.yesBtn.image = SQGetImage(@"pic_denglu_anniu_huise");
        }
    }];
    [self.yesBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        if (weakSelf.emailtextField.formatText.length != 11) {
            [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"请填写正确手机号")];
        } else {
            NumberViewController * vc = [[NumberViewController alloc]init];
            vc.phoneString = weakSelf.emailtextField.formatText;
            [weakSelf SQ_pushViewControllerFull:vc];
        }
    }];
    
}
 
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
- (SQCustomButton *)yesBtn {
    if (!_yesBtn) {
        _yesBtn = [[SQCustomButton alloc]initType:SQCustomButtonTopImageType imageSize:CGSizeMake(48, 48) midmargin:0];
        _yesBtn.image = SQGetImage(@"pic_denglu_anniu_huise");
        _yesBtn.backgroundColor = SQColorF1F1F1;
    }
    return _yesBtn;
}
- (FSTextView *)emailtextField{
    if (!_emailtextField) {
        _emailtextField = [FSTextView textView];
        _emailtextField.placeholder = SQNSLocalString(@"请输入手机号");
        _emailtextField.placeholderColor = SQColor(@"#6B6B6B");
        _emailtextField.font = FONT_REGULAR(14);
        _emailtextField.textColor = SQColor333333;
        _emailtextField.keyboardType = UIKeyboardTypeNumberPad;
        _emailtextField.maxLength = 11;
        _emailtextField.backgroundColor = UIColor.clearColor;
       
    }
    return  _emailtextField;
}
@end
